﻿using Bangle.BLL;
using Bangle.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Main_NodeList : BasePage
{
    private static string FModuleCode = "";

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    #region Ajex获取列表数据

    [WebMethod]
    public static AjexResponseModel GetGridDataHtml(int pageSize, int pageIndex, string OrderField, string QueryString)
    {
        AjexResponseModel response = new AjexResponseModel();

        #region 组装查询条件
        string sWhere = " Valid=0 ";
        sWhere += string.Format(" and CreateUserId={0} ", CurrentSession2.UserID);
        sWhere += string.Format(" and Content like '%{0}%'", QueryString);
        #endregion

        #region 排序
        if (OrderField.Trim().Length > 0)
        {
            OrderField = OrderField.Trim() + ",";
        }
        #endregion

        #region 获取数据
        DataTable dt = null;
        int pCount = 0;
        try
        {
            UtilityBLL ubll = new UtilityBLL();
            dt = ubll.GetListByPage("T_Node", "*", OrderField + "OrderTime", sWhere, pageSize, pageIndex, 1, out pCount);

            #region 生成HTML
            StringBuilder sHtmlString = new StringBuilder();

            string sHtmlModel = "";
            sHtmlModel = @"
                <tr{0}>
                    <td>{1}</td>
                    <td><div class='div-content'>{2}</div></td>
                    <td>{3}</td>
                </tr>
            ";

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                string sNodeId = dt.Rows[i]["NodeId"].ToString();
                string sControl = "";
                sControl += string.Format("<a href=\"javascript:void(0)\" onclick=\"reduction('{0}')\">还原</a>&nbsp;&nbsp;", sNodeId);
                sControl += string.Format("<a href=\"javascript:void(0)\" onclick=\"permanentDelete('{0}')\">删除</a>&nbsp;&nbsp;", sNodeId);
                sHtmlString.Append(string.Format(sHtmlModel
                    , (i % 2 == 0 ? "" : " class='ht-grid-even'")
                    , Convert.ToDateTime(dt.Rows[i]["CreateTime"]).ToString("yyyy-MM-dd")
                    , dt.Rows[i]["Content"].ToString()
                    , sControl
                ));
            }
            #endregion

            response.gridHtml = sHtmlString.ToString();
            response.recordCound = pCount;
            response.pageIndex = pageIndex;
            response.pageSize = pageSize;
        }
        catch (Exception ex)
        {
            response.msg = ex.ToString();
        }
        #endregion

        return response;
    }

    [WebMethod]
    public static string PermanentDelete(string Id)
    {
        T_NodeBLL bll = new T_NodeBLL();
        string sMsg = "";

        try
        {
            bll.Delete(Guid.Parse(Id));
        }
        catch (Exception ex)
        {
            sMsg = "操作失败！";
        }
        return sMsg;
    }

    [WebMethod]
    public static string Reduction(string Id)
    {
        T_Node model = new T_Node();
        T_NodeBLL bll = new T_NodeBLL();
        string sMsg = "";

        try
        {
            model = bll.GetModel(Guid.Parse(Id));
            model.Valid = 1;
            model.UpdateTime = BasePage.GetNowTimeString();
            model.UpdateUserId = BasePage.CurrentSession2.UserID;
            model.OrderTime = BasePage.GetNowTimeString();
            bll.Update(model);
        }
        catch (Exception ex)
        {
            sMsg = "操作失败！";
        }
        return sMsg;
    }

    [WebMethod]
    public static string deleteAll()
    {
        T_NodeBLL bll = new T_NodeBLL();
        string sMsg = "";
        try
        {
            string sWhere = " Valid=0 ";
            sWhere += string.Format(" and CreateUserId={0} ", CurrentSession2.UserID);
            bll.Delete(sWhere);
        }
        catch (Exception ex)
        {
            sMsg = "操作失败！";
        }
        return sMsg;
    }
    #endregion
}